import pyautogui
import time
import commonly_
import os.path

from _log import _log

pyautogui.moveTo(x=0, y=0, duration=0.5, tween=pyautogui.linear)
pyautogui.FAILSAFE = False
pyautogui.PAUSE = 1
application = "便签"
_log = _log(application)
logfile = _log.return_logfile()
logger = _log.return_logger()
commonly = commonly_.Commonly(logfile)
logger.info("*" * 20 + "当前测试程序：" + application + "*" * 20)
os.popen("ukui-notebook")
time.sleep(3)


def text_region(x, y):
    """
   便签应用文本区域
    :return:
    """
    logger.info("便签应用成功打开")
    logger.info("点击便签应用内部出入框")
    pyautogui.click(x + 23, y + 200)
    logger.info("输入文本测试内容:kylinos123五次")
    for i in range(5):
        pyautogui.typewrite(message="kylinos123", interval=0.1)
        pyautogui.press("Enter")
    commonly.screen(application, '输入内容.png', x - 10, y - 10, 320, 320)
    logger.info("截取输入内容")
    pyautogui.click()
    logger.info("全选内容")
    pyautogui.hotkey("Ctrl", "a")
    currx = x + 23
    curry = y + 269
    logger.info("点击功能按钮")
    for i in range(7):
        pyautogui.click(currx, curry)
        currx += 25
        time.sleep(0.5)
        if i == 6:
            pyautogui.press('Esc')
            currx -= 50
        logger.info("点击功能{0}".format(i + 1))
        commonly.screen(application, '设置字体格式{}.png'.format(i), x - 10, y - 10, 320, 320)

    time.sleep(2)
    for i in range(7):
        pyautogui.click(currx, curry)
        currx -= 25
        time.sleep(0.5)
        if i == 6:
            currx += 150
            pyautogui.click(currx, curry)
    logger.info("截图截取设置字体格式")
    commonly.screen(application, '设置字体格式.png', x - 10, y - 10, 320, 320)
    pyautogui.click(currx + 125, curry)
    pyautogui.click(currx + 125, curry + 15)
    logger.info("截图截取更改字号")
    commonly.screen(application, '更改字号.png', x - 10, y - 10, 320, 320)
    pyautogui.click(currx + 150, curry)
    pyautogui.click(currx + 150, curry + 15)
    pyautogui.click(x + 23, y + 200)
    logger.info("截图截取更改字体颜色")
    commonly.screen(application, '更改字体颜色.png', x - 10, y - 10, 320, 320)


def head(x, y):
    """
    便签应用头部
    :return:
    """
    logger.info("测试应用头部")
    pyautogui.moveTo(x + 100, y + 100)
    logger.info("点击选择主题颜色")
    pyautogui.click(x + 210, y + 25)
    currx = x + 50
    curry = y + 65
    pyautogui.click(currx, curry)
    for i in range(7):
        currx += 23
        pyautogui.click(currx, curry)
        logger.info("更改主题颜色{0}".format(i + 1))
        commonly.screen(application, '更改主题颜色{0}.png'.format(i), x - 10, y - 10, 320, 320)
    pyautogui.moveTo(x + 250, y + 30)
    pyautogui.doubleClick()
    pyautogui.click(x + 250, y + 60)
    pyautogui.click()

if __name__ == '__main__':
    logger.info("判断便签应用是否成功打开")
    x, y = commonly.test('Pictures/note_book/便签主页面.png')
    text_region(x, y)
    head(x, y)
